package pikes.mock;

import java.util.Iterator;

import org.junit.Assert;

public final class AssertCollections {

	private AssertCollections() {

	}

	/**
	 * Checks if the expected and actual collections are the same e.g: the elements in both collections equal.
	 * @param <T> any type
	 * @param expected The expected collection
	 * @param actual The actual collection
	 */
	public static <T> void assertEquals(final Iterable<T> expected, final Iterable<T> actual) {
		Assert.assertNotNull("Expected collection cannot be null", expected);
		Assert.assertNotNull("Actual collection cannot be null", actual);

		Iterator<T> iExpected = expected.iterator();
		Iterator<T> iActual = actual.iterator();

		while (iExpected.hasNext()) {
			Assert.assertTrue("Expected to have more elements", iActual.hasNext());

			T expectedT = iExpected.next();
			T actualT = iActual.next();

			Assert.assertEquals(expectedT, actualT);
		}
	}

	/**
	 * Checks if the collection is empty e.g: not null and it has no element
	 * @param <T> any type
	 * @param actual The collection to check
	 * @return true if the collection is empty, false otherwise
	 */
	public static <T> boolean assertEmpty(final Iterable<T> actual) {
		Assert.assertNotNull("Actual collection cannot be null", actual);

		Iterator<T> iActual = actual.iterator();
		return !iActual.hasNext();

	}
}
